class Solution {
public:
    vector<int> nextLargerNodes(ListNode* head) {
        stack<pair<ListNode*, int>> sta;
        vector<int> res;
        int cnt = 0;
        for (ListNode* it = head; it != nullptr; it = it->next) {
            auto& val = it->val;
            while (sta.size() and val > sta.top().first->val) {
                res[sta.top().second] = val;
                sta.pop();
            }
            res.emplace_back(0);
            sta.emplace(pair<ListNode*, int>({ it, cnt++ }));
        }
        return res;
    }
};